package org.subside.util.MybatisConfig;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

/**
 * @Author : zhangbo
 * @data : 2024/4/13
 * @description :
 */
@Configuration
@Component
public class DataSourceConfig {
    @Bean
    public DruidDataSource getDataSource(){
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver"); //驱动
    dataSource.setUrl("jdbc:mysql://localhost:3306/subside?useUnicode=true&characterEncoding=UTF-8&useSSL=false");//连接数据库URL
    dataSource.setUsername("root");//mysql登陆用户名
    dataSource.setPassword("1234");//mysql登陆密码
    dataSource.setMaxActive(100);//连接池最大连接数
    dataSource.setMinIdle(20);//连接池最小连接数
    dataSource.setMaxWait(1000);//连接池超时时间
    return dataSource;
    }

//    @Bean
//    public FactoryBean getFactory(){
//        SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
//        //设置数据源
//        factory.setDataSource(this.getDataSource());
//        //导入mybatis.cfg.xml配置文件信息
//        factory.setConfigLocation(new ClassPathResource("org.subside.Mapper.ConfigMapper.xml"));
//        return factory;
//    }
}
